package Demo01;
import java.util.Scanner;

public class Test {
    public static class TreeNode {
        char val;
        TreeNode left;
        TreeNode right;
        TreeNode(char val) {
            this.val = val;
        }
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String str = in.nextLine();
            TreeNode root = createBinaryTree(str);
            printNode(root);
        }
    }
    public static int count;
    public static TreeNode createBinaryTree(String str) {
        TreeNode node = null;
        if(str.charAt(count)!='#') {
            node= new TreeNode(str.charAt(count++));
            node.left = createBinaryTree(str);
            node.right = createBinaryTree(str);
        } else {
            count++;
        }
        return node;
    }


    public static void printNode(TreeNode node) {
        if(node==null) {
            return;
        }
        System.out.print(node.val+" ");
        printNode(node.left);
        printNode(node.right);
    }
}
